package com.phonepn.mymall.goods.config;

import com.phonepn.mymall.goods.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * webmvc配置器
 *
 * @author quifar
 */
@RefreshScope
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @RefreshScope
    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

    /**
     * 注册 拦截器
     */
    @Override
    public void addInterceptors( InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(tokenInterceptor())
                .addPathPatterns("/**")
                //.excludePathPatterns(patterns)
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }
}
